/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package OilSimNoteBook;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import javax.swing.UIManager;

/**
 *
 * @author anthony
 */
public class App extends OilSimUIComponent implements Observer {

    private JPanel mainPanel;
    CardLayout layout;
    ArrayList<OilSimUIComponent> components;

    public App() {
        mainPanel = new JPanel();
        //layout = new CardLayout();
        //mainPanel.setLayout(layout);

        components = new ArrayList<OilSimUIComponent>();
        init();
    }

    private void init() {
        addComp(new IntroPane());
    }

    public void addComp(OilSimUIComponent comp) {
        components.add(comp);
        comp.addObserver(this);
        mainPanel.removeAll();
        mainPanel.add(comp.getPanel());
        mainPanel.invalidate();

        if (frame != null) {
            frame.pack();
            frame.repaint();
            System.out.println("Repainting frame..");
        }
    }

    @Override
    public Container getPanel() {
        return mainPanel;
    }

    @Override
    public void update(Observable o, Object arg) {
        if (arg.equals(IntroPane.START_CLICKED)) {
            addComp(new LoginPane());
        }else if (arg.equals(LoginPane.LOGIN_CLICKED)) {
            addComp(new Grid());
        
        }
    }

    public static void main(String[] args) {
        try {
            // Set System L&F
        UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
    } 
    catch (Exception e){
        Logger.getLogger("MAIN").log(Level.WARNING, "Unable to set look & feel...");
    }
        
        new App().showFrame();
    }
}
